package com.itheima02;

/**
 * @author Xiao
 * @date 2021/7/11
 */
public class Student {
    private String name;
    private int age;

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Student student = (Student) o;

        if (age != student.age) return false;
        return name != null ? name.equals(student.name) : student.name == null;
    }

    /*@Override
    //重写equals方法 → alt + insert → equals() and hasCode() → 确定… → 删掉hasCode()方法
    public boolean equals(Object o) {   // o = stu2 （向上转型）
        //this --- stu1
        //o    --- stu2

        //判断地址值是否相同
        if (this == o) return true;

        //判断参数o是否为null，两个对象是否来自同一个类
        if (o == null || getClass() != o.getClass()) return false;

        //向下转型
        Student student = (Student) o;

        //比较年龄是否相同
        if (age != student.age) return false;

        //比较姓名内容是否相同
        return name != null ? name.equals(student.name) : student.name == null;
    }*/

    public Student() {
    }

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}
